package com.HangmanCreator;

import android.app.Activity;
import android.content.Intent;
import android.net.MailTo;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.phonegap.*;

public class HangmanCreatorActivity extends DroidGap {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //MyWebViewClient mWebClient = new MyWebViewClient(this);
        //appView.setWebViewClient(mWebClient);
        super.loadUrl("file:///android_asset/www/index.html");

    }

    public class MyWebViewClient extends WebViewClient { 	
    	Activity mContext; 
    	public MyWebViewClient(Activity context){     
    		this.mContext = context; 
    	} 
    	@Override 
    	public boolean shouldOverrideUrlLoading(WebView view, String url) 
    	{          
    	if(url.startsWith("mailto:")){
    	         MailTo mt = MailTo.parse(url);
    	         int urlLength = url.length();
    	         String puzzle = url.substring(7,urlLength);
    	         Intent i = new Intent(Intent.ACTION_SEND);
    	         i.setType("plain/text");
    	         i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    	         //i.putExtra(Intent.EXTRA_EMAIL, new String[]{mt.getTo()});
    	         i.putExtra(Intent.EXTRA_SUBJECT, "Try to solve this hangman game I created");
    	         i.putExtra(Intent.EXTRA_CC, mt.getCc());
    	         i.putExtra(Intent.EXTRA_TEXT, "Follow this link to play a hangman game puzzle I created just for you: \n http://dl.dropbox.com/u/3858223/HangmanCreator/retrievePuzzle.html?sln="+puzzle);
    	         mContext.startActivity(i);
    	         view.reload();
    	         return true;
    	     }
    	     view.loadUrl(url);
    	     return true;
    	 }
    	 }
}

